/**
 * 索引类型
 */

let obj = {
    a: 1,
    b: 2,
    c: 3
}
function getValues(obj: any, keys: string[]) {
    return keys.map(key => obj[key])
}
console.log(getValues(obj, ['a', 'b']))

// keyof T
interface Obj {
    a: number
    b: string
}
let key: keyof Obj

// T[K]
let value: Obj['a']

// T extends U

// 通过上面的三个概念，改造'getValues'

function getValues02<T, K extends keyof T>(obj: T, keys: K[]): T[K][] {
    return keys.map(key => obj[key])
}
console.log(getValues02(obj, ['a', 'b']))
// Type 'string' is not assignable to type '"a" | "b" | "c"'.
// console.log(getValues02(obj, ['e']))










